package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.service.CraftParamDetailService;
import com.uwlaser.service.dto.CraftParamDetailDto;
import com.uwlaser.service.dto.CraftParamDetailQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工艺参数详情管理")
@RequestMapping("/api/craftParamDetail")
public class CraftParamDetailController {

    private final CraftParamDetailService craftParamDetailService;

    @GetMapping
    @Log("查询工艺参数详情")
    @ApiOperation("查询工艺参数详情")
    @PreAuthorize("@el.check('craftParamDetail:list')")
    public ResponseEntity query(CraftParamDetailQueryParam query, Pageable pageable){
        return new ResponseEntity<>(craftParamDetailService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工艺参数详情")
    @ApiOperation("新增工艺参数详情")
    @PreAuthorize("@el.check('craftParamDetail:add')")
    public ResponseEntity create(@Validated @RequestBody CraftParamDetailDto resources){
        return new ResponseEntity<>(craftParamDetailService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工艺参数详情")
    @ApiOperation("修改工艺参数详情")
    @PreAuthorize("@el.check('craftParamDetail:edit')")
    public ResponseEntity update(@Validated @RequestBody CraftParamDetailDto resources){
        craftParamDetailService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工艺参数详情")
    @ApiOperation("删除工艺参数详情")
    @PreAuthorize("@el.check('craftParamDetail:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        craftParamDetailService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询工艺参数")
    @Log("查询工艺参数")
    public ResponseEntity list(CraftParamDetailQueryParam queryParam){
        return new ResponseEntity<>(craftParamDetailService.queryAll(queryParam),HttpStatus.OK);
    }

    /*
    @Log("导出工艺参数详情")
    @ApiOperation("导出工艺参数详情")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('craftParamDetail:list')")
    public void download(HttpServletResponse response, CraftParamDetailQueryParam query) throws IOException {
        craftParamDetailService.download(craftParamDetailService.queryAll(query), response);
    }*/

}
